﻿namespace EasyCMS.Common.Querys
{
    using System;
    using Pismire;



    [System.Runtime.Serialization.DataContractAttribute(Name = "Subject", Namespace = "http://schemas.datacontract.org/2004/07/EasyCMS.Common.Querys")]
    public class Subject : Pismire.Querys.QueryBase
    {
        #region key
        /// <summary>
        /// 缓存键
        /// </summary>
        public override string Key
        {
            get { return string.Format(KeyFormat, CategoryID, AdminID, CodeName); }
        }
        private const string KeyFormat = "Subject_CategoryID{0}AdminID{1}CodeName{2}";
        #endregion

        #region CategoryID
        /// <summary>
        /// CategoryID
        /// </summary>
        public int CategoryID
        {
            get { return m_CategoryID; }
            set
            {
                m_CategoryID = value;
                this.HasCategoryID = (value > -1) ? true : false;
            }
        }
        private int m_CategoryID;
        public bool HasCategoryID { get; private set; }
        public static ExcuteState CategoryID_Validate(ref int categoryID)
        {
            return categoryID.Validation("CategoryID").MoreThan(-1).State;
        }
        #endregion

        #region AdminID
        /// <summary>
        /// AdminID
        /// </summary>
        public int AdminID
        {
            get { return m_AdminID; }
            set
            {
                m_AdminID = value;
                this.HasAdminID = (value > -1) ? true : false;
            }
        }
        private int m_AdminID;
        public bool HasAdminID { get; private set; }
        public static ExcuteState AdminID_Validate(ref int adminID)
        {
            return adminID.Validation("AdminID").MoreThan(-1).State;
        }
        #endregion

        #region CodeName
        /// <summary>
        /// CodeName
        /// </summary>
        public string CodeName
        {
            get { return m_CodeName; }
            set
            {
                m_CodeName = value;
                this.HasCodeName = (!String.IsNullOrEmpty(value)) ? true : false;
            }
        }
        private string m_CodeName;
        public bool HasCodeName { get; private set; }
        public bool CodeNameIsLike { get; set; }
        public static ExcuteState CodeName_Validate(ref string codeName)
        {
            return codeName.Validation("CodeName").LengthBetween(0, 20).Text(ValidationMode.Only).BindValue(ref codeName).State;
        }
        #endregion

        #region checkMe
        /// <summary>
        /// 检查合法性
        /// </summary>
        /// <returns></returns>
        public override ExcuteState CheckMe()
        {
            //初始化
            ExcuteState state = new ExcuteState();

            state = CategoryID_Validate(ref this.m_CategoryID);
            if (!state.Succeed) return state;

            state = AdminID_Validate(ref this.m_AdminID);
            if (!state.Succeed) return state;

            state = CodeName_Validate(ref this.m_CodeName);
            if (!state.Succeed) return state;

            //返回
            return state;
        }
        #endregion
    }
}
